import json
from pathlib import Path
from fastapi import HTTPException
from ..schemas.expression import ExpressionResponse

EXPRESSIONS_FILE = "app/data/expressions.json"  # 建议把文件放在data目录

def get_expressions() -> ExpressionResponse:
    """获取表情包列表服务"""
    try:
        file_path = Path(EXPRESSIONS_FILE)
        if not file_path.exists():
            raise HTTPException(
                status_code=404,
                detail="表情包文件未找到"
            )
        
        with open(file_path, "r", encoding="utf-8") as f:
            content = f.read()
            data = json.loads(content)
            return ExpressionResponse(**data)
            
    except Exception as e:
        raise HTTPException(
            status_code=500,
            detail=f"加载表情包失败: {str(e)}"
        )